<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="android mio4kon mio">
    <meta name="keyword"  content="">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <title>
        
          移动端自动化测试系列之四——生成定位元素 - Mio4kon的博客 | Mio4kon&#39;s Blog
        
    </title>

    <link rel="canonical" href="http://mio4kon.com/2017/04/13/移动端自动化测试系列之四——生成定位元素/">

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/hux-blog.min.css">

    <!-- Pygments Highlight CSS -->
    <link rel="stylesheet" href="/css/highlight.css">

    <!-- Custom Fonts -->
    <!-- <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> -->
    <!-- Hux change font-awesome CDN to qiniu -->
    <link href="https://cdn.staticfile.org/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">


    <!-- Hux Delete, sad but pending in China
    <link href='http://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/
    css'>
    -->


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- ga & ba script hoook -->
    <script></script>
</head>


<!-- hack iOS CSS :active style -->
<body ontouchstart="">

    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Mio4kon</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <!-- Known Issue, found by Hux:
            <nav>'s height woule be hold on by its content.
            so, when navbar scale out, the <nav> will cover tags.
            also mask any touch event of tags, unfortunately.
        -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/">Home</a>
                    </li>

                    

                        
                    

                        
                        <li>
                            <a href="/about/">About</a>
                        </li>
                        
                    

                        
                        <li>
                            <a href="/archives/">Archives</a>
                        </li>
                        
                    

                        
                        <li>
                            <a href="/tags/">Tags</a>
                        </li>
                        
                    
                    
                </ul>
            </div>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        // CLOSE
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        // OPEN
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>


    <!-- Main Content -->
    
<!-- Image to hack wechat -->
<!-- <img src="http://mio4kon.com/img/icon_wechat.png" width="0" height="0"> -->
<!-- <img src="{{ site.baseurl }}/{% if page.header-img %}{{ page.header-img }}{% else %}{{ site.header-img }}{% endif %}" width="0" height="0"> -->

<!-- Post Header -->
<style type="text/css">
    header.intro-header{
        background-image: url('/img/home-bg.jpg')
    }
</style>
<header class="intro-header" >
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <div class="tags">
                        
                          <a class="tag" href="/tags/#移动自动化测试" title="移动自动化测试">移动自动化测试</a>
                        
                    </div>
                    <h1>移动端自动化测试系列之四——生成定位元素</h1>
                    <h2 class="subheading">优雅的生成定位元素</h2>
                    <span class="meta">
                        Posted by Mio4kon on
                        2017-04-13
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

    <!-- Post Container -->
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                post-container">

                <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>之所以把定位元素单独拎出来说,是因为我觉得在写移动端测试框架的时候,如果处理不好的话,元素的定位是比较麻烦的事情.</p>
<p>如果对 <code>Appium</code> 稍微了解的童鞋一定知道定位元素的方式有很多种:</p>
<ul>
<li>id</li>
<li>name</li>
<li>xpath</li>
<li>tag_name</li>
<li>…</li>
</ul>
<p>这么多的查找方式如果都写在代码中如下:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">find_elements_by_id(R.id.login)</div><div class="line">find_elements_by_name(<span class="string">'登录'</span>)</div><div class="line">find_elements_by_xpath(<span class="string">'//android.support.v7.widget.RecyclerView'</span>)</div><div class="line">....</div><div class="line"><span class="comment"># 甚至还有查单个元素的find_element_by_*的方法</span></div></pre></td></tr></table></figure>
<p>如果都写在代码会有什么结果?</p>
<ol>
<li>不直观,不利于查找</li>
<li>如果页面元素发生变动,比如id突然变化.但是整体case没有任何改变.我们还需要去改<strong>代码</strong>.</li>
</ol>
<p>那么如何去解决这两个痛点,就是这篇教程的主要目的,在说到解决痛点之前,我先<strong>简单</strong>介绍几款小框架,在最后会说明为什么结合了这几款小框架就能够解决这两个痛点.如果对着几个小框架毕竟熟悉,可以直接看最后一小节.</p>
<h1 id="PyYAML"><a href="#PyYAML" class="headerlink" title="PyYAML"></a>PyYAML</h1><p>安装</p>
<pre><code>pip3 install PyYAML
</code></pre><p>用于解析 <code>yaml</code> 文件</p>
<p>使用方法非常简单:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">parse</span><span class="params">()</span>:</span></div><div class="line">    L.i(<span class="string">'解析page.yaml, Path:'</span> + pages_path)</div><div class="line">    <span class="keyword">with</span> open(pages_path, <span class="string">'r'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</div><div class="line">        <span class="keyword">return</span> yaml.safe_load(f)</div></pre></td></tr></table></figure>
<p>这样就可以把 <code>yaml</code> 文件的内容解析成一个对象</p>
<h1 id="watchdog"><a href="#watchdog" class="headerlink" title="watchdog"></a>watchdog</h1><p>安装</p>
<pre><code>pip3 install watchdog
</code></pre><p>用于监听某文件是否发生变化,一旦发生变化(保存,删除等)既执行回掉.</p>
<p>先写一个Handler </p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">WatchHandler</span><span class="params">(PatternMatchingEventHandler)</span>:</span></div><div class="line">	<span class="comment"># 监听文件类型</span></div><div class="line">	patterns = [<span class="string">"*.yaml"</span>]</div><div class="line">   <span class="comment"># 想要监听的文件路径</span></div><div class="line">    watch_path = <span class="string">"/Users/mio4kon/.../pages.yaml"</span></div><div class="line"></div><div class="line">    <span class="function"><span class="keyword">def</span> <span class="title">on_created</span><span class="params">(self, event)</span>:</span></div><div class="line">    		<span class="comment"># 比对看看是否真的是想要监听的文件</span></div><div class="line">        <span class="keyword">if</span> self.watch_path == event.src_path:</div><div class="line">            L.i(<span class="string">'监听到文件发生了变化'</span>)</div><div class="line">        <span class="keyword">try</span>:</div><div class="line">            gen_page_py()</div><div class="line">        <span class="keyword">except</span> Exception <span class="keyword">as</span> e:</div><div class="line">            <span class="keyword">pass</span></div></pre></td></tr></table></figure>
<p>使用</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">if</span> __name__ == <span class="string">"__main__"</span>:</div><div class="line">    event_handler = WatchHandler()</div><div class="line">    full_path = event_handler.watch_path</div><div class="line">    path = full_path[:full_path.rfind(<span class="string">'/'</span>) + <span class="number">1</span>]</div><div class="line">    observer = Observer()</div><div class="line">    observer.schedule(event_handler, path)</div><div class="line">    observer.start()</div><div class="line">    <span class="keyword">try</span>:</div><div class="line">        <span class="keyword">while</span> <span class="keyword">True</span>:</div><div class="line">            time.sleep(<span class="number">1</span>)</div><div class="line">    <span class="keyword">except</span> KeyboardInterrupt:</div><div class="line">        observer.stop()</div><div class="line">    observer.join()</div></pre></td></tr></table></figure>
<p>这样的话每当<code>pages.yaml</code>文件发生变化都会执行我定义的<code>gen_page_py()</code>方法.</p>
<p>这些是干什么的用的呢?后面会说到.现在只需要知道 <code>watchdog</code> 能做什么即可.</p>
<h1 id="Jinja2"><a href="#Jinja2" class="headerlink" title="Jinja2"></a>Jinja2</h1><p>安装</p>
<pre><code>pip3 install Jinja2
</code></pre><p>用于生成模板代码.</p>
<p>使用方法</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@staticmethod</span></div><div class="line">   <span class="function"><span class="keyword">def</span> <span class="title">gen_page_py</span><span class="params">()</span>:</span></div><div class="line">       <span class="string">"""</span></div><div class="line">       利用jinja2生成pages.py文件</div><div class="line">       """</div><div class="line">       base_dir = Config.BASE_PATH_DIR</div><div class="line">       template_loader = jinja2.FileSystemLoader(searchpath=base_dir+<span class="string">"/page/template"</span>)</div><div class="line">       template_env = jinja2.Environment(loader=template_loader)</div><div class="line">       page_list = GenPages.gen_page_list()</div><div class="line">       _templateVars = &#123;</div><div class="line">           <span class="string">'page_list'</span>: page_list</div><div class="line">       &#125;</div><div class="line">       template = template_env.get_template(<span class="string">"pages"</span>)</div><div class="line">       <span class="keyword">with</span> open(base_dir+<span class="string">'/page/pages.py'</span>, <span class="string">'w'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</div><div class="line">           f.write(template.render(_templateVars))</div></pre></td></tr></table></figure>
<h1 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h1><p>之所以要用到上面这三个框架.目的是为了将元素定位简单化.并将定位的方式从代码中抽离.方便查找以及修改用例</p>
<p>之前说的两个痛点,我在最初学习 <code>Appium</code> 的时候就深有体会,于是我搜寻了很多相关的测试框架,最终找到一种我认为比较科学的解决方式,其实这个解决方式还是之前在写java测试框架时看过的某一款框架(<a href="https://testerhome.com/topics/6798" target="_blank" rel="external">patatiumAppUi</a>)中用到的方式,不过其作者使用的是xml来定位元素,而且在使用方式上也略微麻烦一点,如果你还有更好的想法,希望能分享出来.</p>
<p>总之通过上述三个框架组合最终不仅解决了上面两个痛点,而且非常易于添加新的元素查找.具体使用方式如下.</p>
<h2 id="开启文件监听"><a href="#开启文件监听" class="headerlink" title="开启文件监听"></a>开启文件监听</h2><p>执行项目中的 <code>watch_dog.py</code></p>
<pre><code>python3 watch_dog.py
</code></pre><h2 id="定位元素"><a href="#定位元素" class="headerlink" title="定位元素"></a>定位元素</h2><p>打开在项目中的<code>pages.yaml</code>文件写入如下内容:</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="meta">---</span></div><div class="line"><span class="attr">LoginPage:</span></div><div class="line"><span class="attr">  dec:</span> 登录页面</div><div class="line"><span class="attr">  locators:</span></div><div class="line"><span class="bullet">    -</span></div><div class="line"><span class="attr">      name:</span> 注册</div><div class="line"><span class="attr">      timeOutInSeconds:</span> <span class="number">20</span></div><div class="line"><span class="attr">      type:</span> name</div><div class="line"><span class="attr">      value:</span> 注册</div></pre></td></tr></table></figure>
<p>保存该文件</p>
<p>至此,文件定位已经完成了.剩下要做的就是在case中用到这个定位的元素了.</p>
<h2 id="使用元素"><a href="#使用元素" class="headerlink" title="使用元素"></a>使用元素</h2><p>使用元素也很简单,下面是点击元素的方法:</p>
<pre><code>action.click(LoginPage.登录)
</code></pre><h2 id="yaml配置说明"><a href="#yaml配置说明" class="headerlink" title="yaml配置说明"></a>yaml配置说明</h2><ul>
<li><code>LoginPage</code> : 主要标识元素所属页面   </li>
<li><code>dec</code>:描述页面,可以省略</li>
<li><code>locators - name</code>: 定位元素的名称  </li>
<li><code>locators - timeOutInSeconds</code>: 超时时间,重试查找的时间,省略后默认是20秒  </li>
<li><code>locators - type</code>: 定位元素方式 </li>
<li><code>locators - value</code>:定位元素的值</li>
</ul>
<h1 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h1><p><a href="http://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank" rel="external">http://pyyaml.org/wiki/PyYAMLDocumentation</a></p>
<p><a href="https://pypi.python.org/pypi/watchdog" target="_blank" rel="external">https://pypi.python.org/pypi/watchdog</a></p>
<p><a href="http://jinja.pocoo.org/docs/2.9/" target="_blank" rel="external">http://jinja.pocoo.org/docs/2.9/</a></p>
<p><a href="https://testerhome.com/topics/6798" target="_blank" rel="external">https://testerhome.com/topics/6798</a></p>


                <hr>

                

                <ul class="pager">
                    
                        <li class="previous">
                            <a href="/2017/04/13/移动端自动化测试系列之五——AppiumLich框架使用/" data-toggle="tooltip" data-placement="top" title="移动端自动化测试系列之五——AppiumLich框架使用">&larr; Previous Post</a>
                        </li>
                    
                    
                        <li class="next">
                            <a href="/2017/04/12/移动端自动化测试系列之三——Allure测试报告/" data-toggle="tooltip" data-placement="top" title="移动端自动化测试系列之三——Allure测试报告">Next Post &rarr;</a>
                        </li>
                    
                </ul>

                

                
                <!-- disqus 评论框 start -->
                <div class="comment">
                    <div id="disqus_thread" class="disqus-thread"></div>
                </div>
                <!-- disqus 评论框 end -->
                

            </div>
    <!-- Side Catalog Container -->
        
            <div class="
                col-lg-2 col-lg-offset-0
                visible-lg-block
                sidebar-container
                catalog-container">
                <div class="side-catalog">
                    <hr class="hidden-sm hidden-xs">
                    <h5>
                        <a class="catalog-toggle" href="#">CATALOG</a>
                    </h5>
                    <ul class="catalog-body"></ul>
                </div>
            </div>
        

    <!-- Sidebar Container -->

            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                
                <section>
                    <!-- no hr -->
                    <h5><a href="/tags/">FEATURED TAGS</a></h5>
                    <div class="tags">
                       
                          <a class="tag" href="/tags/#移动自动化测试" title="移动自动化测试">移动自动化测试</a>
                        
                    </div>
                </section>
                

                <!-- Friends Blog -->
                
                <hr>
                <h5>FRIENDS</h5>
                <ul class="list-inline">

                    
                        <li><a href="http://lrd.ele.me/" target="_blank">lrd ele&#39;s Blog</a></li>
                    
                </ul>
                
            </div>

        </div>
    </div>
</article>




<!-- disqus 公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES * * */
    var disqus_shortname = "hexo-theme-huxblog";
    var disqus_identifier = "http://mio4kon.com/2017/04/13/移动端自动化测试系列之四——生成定位元素/";
    var disqus_url = "http://mio4kon.com/2017/04/13/移动端自动化测试系列之四——生成定位元素/";

    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<!-- disqus 公共JS代码 end -->




<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>
<!-- anchor-js, Doc:http://bryanbraun.github.io/anchorjs/ -->
<script>
    async("https://cdn.bootcss.com/anchor-js/1.1.1/anchor.min.js",function(){
        anchors.options = {
          visible: 'always',
          placement: 'right',
          icon: '#'
        };
        anchors.add().remove('.intro-header h1').remove('.subheading').remove('.sidebar-container h5');
    })
</script>
<style>
    /* place left on bigger screen */
    @media all and (min-width: 800px) {
        .anchorjs-link{
            position: absolute;
            left: -0.75em;
            font-size: 1.1em;
            margin-top : -0.1em;
        }
    }
</style>



    <!-- Footer -->
    <!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                
                
                

                
                    <li>
                        <a target="_blank" href="http://weibo.com/u/3198010790">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-weibo fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                

                
                    <li>
                        <a target="_blank"  href="https://github.com/Mio4kon">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                

                </ul>
                <p class="copyright text-muted">
                    Copyright &copy; Mio4kon 2019 
                    <br>
                    Theme by <a href="http://huangxuan.me">Hux</a> 
                    <span style="display: inline-block; margin: 0 5px;">
                        <i class="fa fa-heart"></i>
                    </span> 
                    Ported by <a href="http://blog.kaijun.rocks">Kaijun</a> | 
                    <iframe
                        style="margin-left: 2px; margin-bottom:-5px;"
                        frameborder="0" scrolling="0" width="91px" height="20px"
                        src="https://ghbtns.com/github-btn.html?user=kaijun&repo=hexo-theme-huxblog&type=star&count=true" >
                    </iframe>
                </p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="/js/bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="/js/hux-blog.min.js"></script>


<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!-- 
     Because of the native support for backtick-style fenced code blocks 
     right within the Markdown is landed in Github Pages, 
     From V1.6, There is no need for Highlight.js, 
     so Huxblog drops it officially.

     - https://github.com/blog/2100-github-pages-now-faster-and-simpler-with-jekyll-3-0  
     - https://help.github.com/articles/creating-and-highlighting-code-blocks/    
-->
<!--
    <script>
        async("http://cdn.bootcss.com/highlight.js/8.6/highlight.min.js", function(){
            hljs.initHighlightingOnLoad();
        })
    </script>
    <link href="http://cdn.bootcss.com/highlight.js/8.6/styles/github.min.css" rel="stylesheet">
-->


<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("http://mio4kon.com/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

<!--fastClick.js -->
<script>
    async("https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>


<!-- Google Analytics -->




<!-- Baidu Tongji -->


<!-- Side Catalog -->

<script type="text/javascript">
    function generateCatalog (selector) {
        var P = $('div.post-container'),a,n,t,l,i,c;
        a = P.find('h1,h2,h3,h4,h5,h6');
        a.each(function () {
            n = $(this).prop('tagName').toLowerCase();
            i = "#"+$(this).prop('id');
            t = $(this).text();
            c = $('<a href="'+i+'" rel="nofollow">'+t+'</a>');
            l = $('<li class="'+n+'_nav"></li>').append(c);
            $(selector).append(l);
        });
        return true;    
    }

    generateCatalog(".catalog-body");

    // toggle side catalog
    $(".catalog-toggle").click((function(e){
        e.preventDefault();
        $('.side-catalog').toggleClass("fold")
    }))

    /*
     * Doc: https://github.com/davist11/jQuery-One-Page-Nav
     * Fork by Hux to support padding
     */
    async("/js/jquery.nav.js", function () {
        $('.catalog-body').onePageNav({
            currentClass: "active",
            changeHash: !1,
            easing: "swing",
            filter: "",
            scrollSpeed: 700,
            scrollOffset: 0,
            scrollThreshold: .2,
            begin: null,
            end: null,
            scrollChange: null,
            padding: 80
        });
    });
</script>





<!-- Image to hack wechat -->
<img src="http://mio4kon.com/img/icon_wechat.png" width="0" height="0" />
<!-- Migrate from head to bottom, no longer block render and still work -->

</body>

</html>
